package com.sangeng.controller;

import com.sangeng.dto.AddCategoryDTO;
import com.sangeng.dto.UpdateCategoryDTO;
import com.sangeng.entity.ResponseResult;
import com.sangeng.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/content/category")
@RestController
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @GetMapping("/listAllCategory")
    public ResponseResult getAllCategory(){

      return   categoryService.getAllCategory();
    }
@GetMapping("/list")
    public ResponseResult getCategoryList(Integer pageNum,Integer pageSize){

        return  categoryService.getCategoryList(pageNum,pageSize);


    }

    @PostMapping
    public ResponseResult addCategory(@RequestBody AddCategoryDTO addCategoryDTO){

      return   categoryService.addCategory(addCategoryDTO);

    }

    @DeleteMapping("/{idList}")
    public ResponseResult deleteCategory(@PathVariable List<Long> idList){

      return   categoryService.deleteCategoryById(idList);

    }
    @GetMapping("/{id}")
    public ResponseResult getCategoryById(@PathVariable Long id){

        return categoryService.getCategoryById(id);


    }

    @PutMapping
    public ResponseResult updateCategory(@RequestBody UpdateCategoryDTO updateCategoryDTO){

        return categoryService.updateCategory(updateCategoryDTO);


    }

}
